<?php

namespace app\shop\model\company;

use think\Model;
use think\model\concern\SoftDelete;
use app\shop\model\user\User;
/**
 * 应用模型
 */
class Station extends Model
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;
    protected $table = 'tp_department_station';

    public function trainerUser()
    {
        return $this->belongsTo(User::class, 'trainer', 'user_id')->withDefault();
    }

    public function trainFile()
    {
        return $this->hasMany(TrainFile::class, 'station_id', 'id');
    }

    public function students()
    {
        return $this->hasMany(TrainStudent::class, 'station_id', 'id');
    }

    //获取学员数量
    public function getStudentCountAttr($value, $data)
    {
        return TrainStudent::where('station_id', $data['id'])->count();
    }

    public function department()
    {
        return $this->belongsTo(Department::class, 'department_id', 'id')->withDefault();
    }
}
